package com.cz.shopping.excpetion;

import com.cz.shopping.model.vo.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description <>
 * @author: zhouchaoyu
 * @Date: 2023-10-25
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return Result.build(null, 201, "出现了异常");
    }

    @ExceptionHandler(value = CustomException.class)     // 处理自定义异常
    @ResponseBody
    public Result error(CustomException exception) {
        exception.printStackTrace();
        return Result.build(null , exception.getResultCodeEnum()) ;
    }

}
